<?php

namespace app\admin\validate;

use think\Validate;

class Permission extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */	
	protected $rule = [
        'ids|标识列表' => 'require|array',
	    'name|节点名' => 'chsDash',
        'category_id|分组' => 'integer',
        'status|状态' => 'in:-1,0,1',
        'start_create_at|创建时间开始范围' => 'date',
        'description|描述' => 'require|max:100',
        'end_create_at|创建时间结束范围' => 'date',
        'path|路径' => 'require'
    ];
    
    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */	
    protected $message = [];

    /**
     * 场景验证
     * @var []
     */
    protected $scene = [
        'index' => ['name','category_id','status','start_create_at','end_create_at']
    ];

    /**
     * 定义验证新增场景验证
     * @return $this
     */
    public function sceneCreate()
    {
        return $this->only(['name','description', 'status','category_id','path'])
            ->append('name', 'require')
            ->append('status', 'require')
            ->append('category_id', 'require');
    }

    /**
     * 定义验证编辑场景验证
     * @return $this
     */
    public function sceneUpdate()
    {
        return $this->only(['name','description', 'status','category_id','path'])
            ->append('name', 'require')
            ->append('status', 'require')
            ->append('category_id', 'require');
    }

    /**
     * 定义批量删除场景验证
     * @return $this
     */
    public function sceneDestory()
    {
        return $this->only(['ids']);
    }
}
